// pages/home/home.js



Page({

  /**
   * 页面的初始数据
   */
  data: {
   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) { 
    this.setData({
      id: options.id
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  login: function () {
    var that = this; 
   wx.request({
     url: 'http://47.92.245.109:8080/panduan',

     data: {
       openid:that.data.id
      },
     header: {
       'content-type': 'application/json' //默认值
     },
     success: function (res) {
      if(res.data.a==1){
        wx.navigateTo({
                                     
          url: '../two-dimensional code/two-dimensional code?id='+that.data.id
           
          })        
      }else{
        wx.navigateTo({
                                     
          url: '../scan/scan?id='+that.data.id
           
          })      
      }

     }

   })
            
  },


  register: function () {
    var that = this;
    wx.request({
      url: 'http://47.92.245.109:8080/find',
 
      data: {
        openid:that.data.id
       },
      header: {
        'content-type': 'application/json' //默认值
      },
      success: function (res) {
        
      
        console.log(res.data);
          that.setData({
            list:res.data
          
          })
    }
  })
  },

  loginForm: function (data) {
    var that = this;
    var name = data.detail.value.name
    var houseid = data.detail.value.houseid
    var cardid = data.detail.value.cardid
    var account = data.detail.value.account
    var password = data.detail.value.password
    
    wx.request({
      url: 'http://47.92.245.109:8080/update',
      method: "POST",
      data: {
        openid:that.data.id,
        cardid: data.detail.value.cardid,
        houseid: data.detail.value.houseid,
        name: data.detail.value.name,
        account: data.detail.value.account,
        password: data.detail.value.password,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        wx.showToast({

          title: '提交成功',
           
          icon: 'success',
           
          duration: 2000,

          success:function(){
                                     
                                    wx.navigateTo({
                                     
                                    url: '../home/home?id='+that.data.id
                                     
                                    })
                                  }

      })
      }

    })
  },
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

})